<?php  if ( ! defined('SERVER_ROOT')) exit('No direct script access allowed');

/**
 * Fetch and then removes values from array of parameters
 *
 * @param string $value value to search for in parameters
 * @param array $params array of parameters to search
 * @param bool $next determines if next value is to be returned
 *
 * @return mixed return velue if found in parameters or false if not
 * 
 */
function fetchParam($value,&$params,$next=FALSE) {
    // set default return
    $return = FALSE;
    // get index of value in paremeter array
    $index = array_search($value,$params);
    // test if value is in array
    if( in_array($value,$params) ){
        // return value found or next value if $next is true
        $return = ($next) ? $params[$index+1] : $value;
        // unset value at index in parameter array
        unset($params[$index]);
        // unset next value if $next is true
        if($next) unset($params[$index+1]);
    }
    return $return;
}
